﻿using Timeline.Inis;
using Timeline.Utils;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

// The Content Dialog item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238

namespace Timeline.Pages {
    public sealed partial class R22Dlg : ContentDialog {
        private readonly R22DlgInput input = null; // 用于回传参数

        public R22Dlg(string comment, string anser, R22DlgInput input) {
            this.InitializeComponent();

            this.input = input;

            BoxR22Code.Text = comment ?? "";
            BoxR22Answer.Text = anser ?? "";
            BoxR22Answer.Visibility = !string.IsNullOrEmpty(comment) || !string.IsNullOrEmpty(anser)
                ? Visibility.Visible : Visibility.Collapsed;

            this.IsPrimaryButtonEnabled = !string.IsNullOrEmpty(comment);
        }

        private void BoxR22Code_TextChanged(object sender, TextChangedEventArgs e) {
            this.IsPrimaryButtonEnabled = BoxR22Code.Text.Trim().Length > 0;
        }

        private void LinkDonate_Click(Windows.UI.Xaml.Documents.Hyperlink sender, Windows.UI.Xaml.Documents.HyperlinkClickEventArgs args) {
            this.Hide();
            _ = new DonateDlg {
                RequestedTheme = ThemeUtil.ParseTheme(IniUtil.GetIniTheme()) // 修复未响应主题切换的BUG
            }.ShowAsync();
        }

        private void DlgR22_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args) {
            if (this.input != null) {
                this.input.Comment = BoxR22Code.Text;
            }
        }

        public class R22DlgInput {
            public string Comment { get; set; }
        }
    }
}
